<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    (function () {
        function Observe() {
            this.list = {};
            this.on = function (type, handler) {
                this.list[type] = this.list[type] || [];
                this.list[type].push(handler);
            }
            this.emit = function (type, msg) {
                this.list[type] &&
                this.list[type].forEach((item) => {
                        item(msg);
                    })
                }
            }
            window.Observe = Observe;
        })()

        //实例化对象
        var os = new Observe();

    //订阅消息
    os.on('lijiaqi', function (msg) {
        //接收来自发布者的消息msg
        console.log('李莉 收到了来自lijiaqi的消息'+msg);
    })
    //订阅消息
    os.on('lijiaqi', function (msg) {
        //接收来自发布者的消息msg
        console.log('李丽 收到了来自lijiaqi的消息'+msg);
    })
    //订阅消息
    os.on('lijiaqi', function (msg) {
        //接收来自发布者的消息msg
        console.log('莉莉 收到了来自lijiaqi的消息'+msg);
    })

    //发布消息
    os.emit('lijiaqi','一起来买买买')
</script>